local junshu = fk.CreateSkill{
  name = "hanqing__junshu",
  tags = { Skill.Limited },
}

Fk:loadTranslationTable{
  ["hanqing__junshu"] = "均输",
  [":hanqing__junshu"] = "限定技，出牌阶段，你可以令一名角色视为使用三张<a href=':redistribute'>【调剂盐梅】</a>，若因此使所有体力值"..
  "与其相等的角色的手牌数均相等，其视为使用一张【桃】，你重置〖均输〗。",

  ["#hanqing__junshu"] = "均输：你可以令一名角色视为使用三张【调剂盐梅】！",
  ["#hanqing__junshu-use"] = "均输：请视为使用【调剂盐梅】（还剩%arg张！）",
}

junshu:addEffect("active", {
  anim_type = "support",
  card_num = 0,
  target_num = 1,
  prompt =  "#hanqing__junshu",
  can_use = function (self, player)
    return player:usedSkillTimes(junshu.name, Player.HistoryGame) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected)
    if #selected == 0 then
      local card = Fk:cloneCard("redistribute")
      card.skillName = junshu.name
      return #card:getAvailableTargets(to_select) > 1
    end
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    for i = 1, 3, 1 do
      if target.dead or
        not room:askToUseVirtualCard(target, {
        name = "redistribute",
        skill_name = junshu.name,
        prompt = "#hanqing__junshu-use:::"..(4 - i),
        cancelable = false,
      }) then
        break
      end
    end
    if target.dead then return end
    if table.every(room.alive_players, function (p)
      if p.hp == target.hp then
        return p:getHandcardNum() == target:getHandcardNum()
      else
        return true
      end
    end) then
      player:setSkillUseHistory(junshu.name, 0, Player.HistoryGame)
      room:useVirtualCard("peach", nil, target, target, junshu.name)
    end
  end,
})

return junshu
